/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.lcfgly.Service;

import com.lcfgly.Dao.ImgsImpl;
import com.lcfgly.Database.ShopImgs;
import com.lcfgly.Exception.ActionException;
import com.lcfgly.Exception.ErrorException;
import java.io.Serializable;
import java.sql.SQLException;
import java.util.Date;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

/**
 *
 * @author lcfgly
 */
public class ImgsService implements Serializable{
    
    Logger log=Logger.getLogger("SqlError");
    
    @Autowired
    ImgsImpl imgsImpl;
    
    /**
     * 保存图片
     * @param arg0
     * @return
     * @throws ActionException 
     */
    public boolean save(ShopImgs arg0) throws ActionException{
        if(arg0 == null)
            return false;
        else if(arg0.getImgurl() == null)
            throw new ActionException("空数据");
        else if(arg0.getUserid()== 0)
            throw new ActionException("未检测到用户信息");
        else if(arg0.getUpdatetime()== null)
            arg0.setUpdatetime(new Date(new Date().getTime()));
        if(arg0.getId() == null){
            try{
                return imgsImpl.insert(arg0) == 1;
            }catch(SQLException e){
                log.error(e);
                throw new ErrorException();
            }
        }else{
            try{
                return imgsImpl.update(arg0) == 1;
            }catch(SQLException e){
                log.error(e);
                throw new ErrorException();
            }
        }
    }
    
}
